#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/9/15 21:41
# @Author: 徐洪英
# @Email: xx@gmail.com
# @File：add_receivable_page.py



from selenium.webdriver.common.by import By
from config.config import HOST
from time import sleep
from pages.base_page import BasePage
class CrmAddRiePage(BasePage):
    """类属性"""
    url="http://{}/crm/index.php?m=finance&a=add&t=receivables".format(HOST)

    ys_name_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tbody/tr[2]/td[2]/input")  # 应收款名
    contract_name_locator = (By.ID, "contract_name")  # 合同
    contract_locator = (By.XPATH, "/html/body/div[8]/div[2]/table/tbody[2]/tr[1]/td[1]/input")
    ui_locator = (By.XPATH, "/html/body/div[8]/div[3]/div/button[1]")  # 合同ok按钮
    pay_time_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tbody/tr[8]/td[2]/input")  # 收款时间
    check_add_order_locator = (By.ID, "check_add_order")  # 点击同时创建收款单
    order_money_locator = (By.ID, "order_money")  # 收款金额
    description_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tbody/tr[9]/td[2]/textarea")  # 描述
    sk_submit_locator = (By.NAME, "submit")  # 保存
    alert_add_success_locator = (By.XPATH, "/html/body/div[5]/div[2]")  # 断言添加成功
    cat_locator = (By.LINK_TEXT, "查看")  # 查看)
    return_locator = (By.LINK_TEXT, "返回")  # 返回
    def add_rie_input(self,ys_name):
        """输入应收款名"""
        self.driver.find_element(*self.ys_name_locator).send_keys(ys_name)
    def click_contract_name(self):
        """点击合同"""
        self.driver.find_element(*self.contract_name_locator).click()
        sleep(2)
    def choose_contract_name(self):
        """选择合同"""
        self.driver.find_element(*self.contract_locator).click()
        sleep(2)
    def click_ui(self):
        """点击ok键"""
        self.driver.find_element(*self.ui_locator).click()
    def check_add_order(self):
        """选择同时创建收款单"""
        self.driver.find_element(*self.check_add_order_locator).click()
    def order_money_input(self,money):
        """输入收款金额"""
        self.driver.find_element(*self.order_money_locator).send_keys(money)
    def pay_time_input(self,time):
        """输入收款时间"""
        self.driver.find_element(*self.pay_time_locator).send_keys(time)
    def description_input(self,description):
        """输入描述"""
        self.driver.find_element(*self.description_locator).send_keys(description)
    def click_sk_submit(self):
        """点击保存"""
        self.driver.find_element(*self.sk_submit_locator).click()
    def click_cat_rid(self):
        """查看应收信息"""
        self.driver.find_element(*self.cat_locator).click()  # 点击查看
        sleep(2)
    def click_return(self):
        """点击返回"""
        self.driver.find_element(*self.return_locator).click()  # 返回
    def actual_stutas(self):
        """断言添加应收款"""
        actual = self.driver.find_element(*self.alert_add_success_locator).text
        return actual

    def actual_cat_stutas(self):
        """断言查看应收款"""
        actual = self.driver.current_url
        return actual




    # def add_receivable(self,ys_name,money,description):
    #     self.add_rie_input(ys_name)#输入应收款名
    #     self.click_contract_name()#点击合同
    #     self.choose_contract_name()#选择合同
    #     self.click_ui()
    #     self.check_add_order()
    #     self.order_money_input()
    #     self.pay_time_input(money)
    #     self.description_input(description)
    #     self.click_sk_submit()

